// index.js
// 获取应用实例
const app = getApp();
const API_URL = "http://sahar.aynakedu.com/api/";

Page({
  data: {
    curBar:0,
    current:0,
    cardCur: 0,
    customBar:app.globalData.CustomBar,
    swiperList: [{
      id: 0,
      type: 'image',
      url: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big84000.jpg'
    }, {
      id: 1,
        type: 'image',
        url: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big84001.jpg',
    }, {
      id: 2,
      type: 'image',
      url: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big39000.jpg'
    }, {
      id: 3,
      type: 'image',
      url: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big10001.jpg'
    }, {
      id: 4,
      type: 'image',
      url: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big25011.jpg'
    }, {
      id: 5,
      type: 'image',
      url: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big21016.jpg'
    }, {
      id: 6,
      type: 'image',
      url: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big99008.jpg'
    }],
    scrollTop:0,
    userInfo:null,
  },
  
  onLoad() {
    
  },

  // 获取用户信息和实现登录
  getUserInfoAndLogin(e){
    let that = this;
    wx.getUserProfile({
      desc: '获取用户信息',
      success(res){
        wx.login({
          success(res1){
            console.log(res1.code);
            wx.request({
              url: API_URL+'wxLogin',
              data:{'code':res1.code,'userInfo':res.userInfo},
              method:'POST',
              success(res2){
                console.log(res2);
                that.setData({
                  userInfo:res2.data.userInfo,
                });
              },
              fail(err2){

              }
            })
          }
        })
      },
      fail(err){
        console.log(err);
      }
    })
  },

  changeBar(e){
    let index = e.currentTarget.dataset.index;
    if(!index){
      index = e.detail.current;
    }
    this.setData({
      curBar:index,
      current:index
    });
  },

  cardSwiper(e) {
    this.setData({
      cardCur: e.detail.current
    })
  },

  getScroll(e){
    let scrollTop = e.detail.scrollTop;
    this.setData({
      scrollTop:scrollTop,
    });
  },

})
